package algocity.view.windows;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.AbstractButton;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;

import algocity.view.Boton;
import algocity.view.ConstanteImagenes;

public class PanelMenuInicial extends JPanel {

	private static final long serialVersionUID = 1798377663599407297L;
	
	private static final Insets insets = new Insets(50,0,0,0);
	
	public AbstractButton botonIniciarPartida;
	public AbstractButton botonContinuarPartida;
	public AbstractButton botonPuntajes;
	AbstractButton botonSalir;
	JLabel labelTitulo;
	
	public PanelMenuInicial(ActionListener a){
		super();
		setLayout(new GridBagLayout());
		botonIniciarPartida = new Boton("Iniciar Partida",a);
		botonContinuarPartida = new Boton("Continuar Partida",a);
		botonPuntajes = new Boton("Ver Puntajes",a);
		botonSalir = new Boton("Salir",a);
		botonSalir.addMouseListener(new MouseAdapter(){
								public void mousePressed(MouseEvent e){
									System.exit(0);
								}});
		labelTitulo = new JLabel("AlgoCity",JLabel.CENTER);
		labelTitulo.setFont(new Font("Serif",Font.BOLD,50));
		labelTitulo.setAlignmentX(CENTER_ALIGNMENT);
		addComponent(this,labelTitulo,1,0,1,1,GridBagConstraints.CENTER,GridBagConstraints.BOTH);
		addComponent(this,botonIniciarPartida,1,1,1,1,GridBagConstraints.CENTER,GridBagConstraints.BOTH);
		addComponent(this,botonContinuarPartida,1,2,1,1,GridBagConstraints.CENTER,GridBagConstraints.BOTH);
		addComponent(this,botonPuntajes,1,3,1,1,GridBagConstraints.CENTER,GridBagConstraints.BOTH);
		addComponent(this,botonSalir,1,4,1,1,GridBagConstraints.CENTER,GridBagConstraints.BOTH);
		addComponent(this,new JLabel(),0,0,1,1,GridBagConstraints.CENTER,GridBagConstraints.BOTH);
		addComponent(this,new JLabel(),2,5,1,1,GridBagConstraints.CENTER,GridBagConstraints.BOTH);
		
	}

	private void addComponent(JPanel panel, Component component,
			int gridx, int gridy, int gridwidth, int gridheight, int anchor, int fill) {
		GridBagConstraints gbc = new GridBagConstraints(gridx, gridy,
		gridwidth, gridheight, 1.0, 1.0, anchor, fill, insets, 0, 0);
		panel.add(component, gbc);
	}	
	
	public void paint(Graphics g){
		Dimension tamanio = this.getSize();
		String ruta = ConstanteImagenes.fondoMenu;
		ImageIcon img = new ImageIcon(getClass().getResource(ruta));
		g.drawImage(img.getImage(),0,0,tamanio.width,tamanio.height,null);
		setOpaque(false);
		super.paint(g);
	}

}
